import {TimeSelect} from 'element-ui';
import {valueEquals} from 'element-ui/lib/utils/util';

TimeSelect.mixins[0].watch.value = undefined;

export default {
  name: TimeSelect.name,
  mixins: [TimeSelect],
  watch: {
    value: function value(val, oldVal) {
      if (!valueEquals(val, oldVal) && !this.pickerVisible && this.validateEvent) {
        this.$nextTick(() => {
          this.dispatch('ElFormItem', 'el.form.change', val);
        });
      }
    }
  },
  methods: {
    emitChange: function emitChange(val) {
      // determine user real change only
      if (!valueEquals(val, this.valueOnOpen)) {
        this.$emit('change', val);
        this.valueOnOpen = val;
        if (this.validateEvent) {
          this.$nextTick(() => {
            this.dispatch('ElFormItem', 'el.form.change', val);
          });
        }
      }
    },
  },
};
